def isPrime(z):   
    if z == 1: return False   
    test = True   
    k = z - 1   
    while k > 1:   
        if not z % k:   
            test = False               
            break   
        k -= 1       
    return test  
     
a = input() 
r = [] 
for i in range(len(a) + 1): 
    for k in range(i,len(a) + 1): 
        if i == k: 
            continue 
        n = int(a[i:k]) 
        if isPrime(n): 
            r += [n] 
print(max(r) if r else 0)
